package com.user.util;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

public class SMSUtils {
    public static final String CODE ="SMS_171852443";
    public static boolean sendShortMessage(String templateCode,String phoneNumbers,String param) throws ClientException {
        System.setProperty("sun.net.client.defaultConnectTimeout","10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        final String product ="Dysmsapi";
        final String domain="dysmsapi.aliyuncs.com";
        final String accessKeyId ="LTAI5tQDoMFyok8uHDXYrkr5";
        final String accessKeySecret="M5617ILDQGcZXhntcLVupiIsvJD23e";
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou","cn-hangzhou",product,domain);
        DefaultAcsClient acsClient = new DefaultAcsClient(profile);
        SendSmsRequest request = new SendSmsRequest();
        request.setMethod(MethodType.POST);
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName("健康体检中心");
        request.setTemplateCode(templateCode);
        request.setTemplateParam("{\"code\":\""+param+"\"}");
        SendSmsResponse acsResponse = acsClient.getAcsResponse(request);
        if (acsResponse.getCode() != null && acsResponse.getCode().equals("OK")) {
            System.out.println("请求成功!!   "+ acsResponse.getMessage());
            return true;
        }else{
            System.out.println(acsResponse.getMessage());
            return false;
        }
    }
}
